<?php

declare(strict_types=1);

namespace App\CustHub\Controller\Admin;

use App\CustHub\Controller\BaseController;
use App\CustHub\Service\ChDevelopCourseService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Mine\Annotation\Auth;
use Mine\Annotation\Permission;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: "ch/admin/developCourse"),auth]
class ChDevelopCourseController extends BaseController
{
    #[Inject]
    protected ChDevelopCourseService $service;

    /**
     * 发展列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[GetMapping("index"),Permission("ch:admin:developCourse:index")]
    public function getDevelopCourseList()
    {
        return $this->success($this->service->getPageList($this->request->all()));
    }

    /**
     * 新增
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping("save"),Permission("ch:admin:developCourse:save")]
    public function saveDevelopCourse()
    {
        return $this->success(['id' => $this->service->save($this->request->all())]);
    }

    /**
     * 修改
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PutMapping("update/{id}"),Permission("ch:admin:developCourse:update")]
    public function updateDevelopCourse(int $id)
    {
        return $this->service->update($id,$this->request->all())?$this->success():$this->error();
    }

    /**
     * 删除
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[DeleteMapping("delete"),Permission("ch:admin:developCourse:delete")]
    public function deleteDevelopCourse()
    {
        return $this->service->delete((array) $this->request->input('ids', []))?$this->success():$this->error();
    }
}